"""
线性查找法/顺序查找法
"""


def linear_search(target_list: list, target_key: int) -> int:
    """
    :param target_list: 待查找的列表
    :param target_key:  查找的目标值
    :return:    返回查找结果索引值，未查找到则返回-1
    """
    for i in range(len(target_list)):
        if target_key == target_list[i]:
            return i  # "在第{0}位".format(i + 1)
        else:
            continue
    return -1  # "未查找到索引值"


test_list = [1, 4, 16, 8, 8, 10]
test_key = 8
print(linear_search(test_list, test_key))
# 输出结果：
# 3
